gusucode.com > VC++ 汽配销售管理系统(Access)源码程序 > VC++ 汽配销售管理系统(Access)源码程序/源码/DStoreQuwery.cpp
//Download by http://www.NewXing.com // DStoreQuwery.cpp : implementation file // #include "stdafx.h" #include "qpglxt.h" #include "DStoreQuwery.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CQpglxtApp theApp; ///////////////////////////////////////////////////////////////////////////// // CDStoreQuwery dialog CDStoreQuwery::CDStoreQuwery(CWnd* pParent /*=NULL*/) : CDialog(CDStoreQuwery::IDD, pParent) { //{{AFX_DATA_INIT(CDStoreQuwery) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CDStoreQuwery::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDStoreQuwery) DDX_Control(pDX, IDC_STASumNumber, m_StaSumNumber); DDX_Control(pDX, IDC_STASumMoney, m_StaSumMoney); DDX_Control(pDX, IDC_BASEQUERY_GRID, m_Grid); DDX_Control(pDX, IDC_BASEQUERY_EDTCONDITION, m_EdtCondition); DDX_Control(pDX, IDC_BASEQUERY_COMEMBLEM, m_ComEmblem); DDX_Control(pDX, IDC_BASEQUERY_COMFIELD, m_ComField); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDStoreQuwery, CDialog) //{{AFX_MSG_MAP(CDStoreQuwery) ON_BN_CLICKED(IDC_BUT_QUERY, OnButQuery) ON_BN_CLICKED(IDC_BUT_PRINT, OnButPrint) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDStoreQuwery message handlers void CDStoreQuwery::OnOK() { // TODO: Add extra validation here //CDialog::OnOK(); } BOOL CDStoreQuwery::OnInitDialog() { CDialog::OnInitDialog(); rst.Open("库存查询"); this->m_ComField.SetFieldset(rst); m_Grid.ReadOnly(true); this->m_ComEmblem.SetCurSel(0); this->m_ComField.SetCurSel(0); this->m_ComField.m_CurrentFieldType="字符型"; m_Grid.SetDataBase("库存查询",adCmdTable); Total("SELECT * FROM 库存查询"); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CDStoreQuwery::OnButQuery() { CString sSQL,sField,sEmblem,sCondition; this->m_ComField.GetWindowText(sField); this->m_ComEmblem.GetWindowText(sEmblem); this->m_EdtCondition.GetWindowText(sCondition); //判断查询字段的类型 if(m_ComField.m_CurrentFieldType=="数值型") sSQL.Format("SELECT * FROM %s WHERE %s %s %s","库存查询",sField,sEmblem,sCondition); if(m_ComField.m_CurrentFieldType=="字符型") { if(sEmblem!="LIKE") sSQL.Format("SELECT * FROM %s WHERE %s %s '%s'","库存查询",sField,sEmblem,sCondition); else sSQL.Format("SELECT * FROM %s WHERE %s %s '%s%%'","库存查询",sField,sEmblem,sCondition); } if(m_ComField.m_CurrentFieldType=="日期型") { sSQL.Format("SELECT * FROM %s WHERE %s %s #%s#","库存查询",sField,sEmblem,sCondition); } rst.Open(sSQL,adCmdText); m_Grid.AddCellValue(rst); Total(sSQL); } void CDStoreQuwery::Total(CString sSQL) { CString sNewSQL,sSumNumber; sNewSQL.Format("SELECT sum(库存数量) AS 合计数量 ,sum(合计金额) AS 库存金额 FROM (%s) DERIVEDTBL",sSQL); RxRecordset rRst; rRst.Open(sNewSQL,adCmdText); if(rRst.GetRecordCount()<1) return; m_StaSumNumber.SetWindowText("合计数量:"+rRst.GetFieldValue("合计数量")); m_StaSumMoney.SetWindowText("库存金额:"+rRst.GetFieldValue("库存金额")); } void CDStoreQuwery::OnButPrint() { CString sCount,sSumMoney,sSumNumber; sCount.Format("%d",rst.GetRecordCount()); this->m_StaSumMoney.GetWindowText(sSumMoney); this->m_StaSumNumber.GetWindowText(sSumNumber); m_ps.MainCaptionFontSize=400; m_ps.DeckCaptionFontSize=180; m_ps.DeckCaptionNumber=0; m_ps.TotalNumber=2; m_ps.Totals[0]=sSumNumber; m_ps.Totals[1]=sSumMoney; m_ps.Grid=&m_Grid; theApp.Print(); }